package com.example.onehundreddoor;

import java.util.ArrayList;
import java.util.List;

public class DoorController {


    private List<Door> doors;

    DoorController(){
        doors = new ArrayList<>();
        for (int i = 1; i < 101; i++) {
            doors.add(new Door(i,false));
        }
    }

    public void pass(int times){
        for (int i = 1; i <= times; i++) {
            changeDoor(i);
        }
    }

    private void changeDoor(int step){
        for (int i = step; i <= 100; i = i+step) {
            Door door = doors.get(i-1);
            door.changeState();
        }
    }

    public boolean getDoorState(int i ){
        return doors.get(i-1).isOpen();
    }


    public int getOpenDoorNum(){
        return (int) doors.stream().filter(Door::isOpen).count();
    }


}
